<?php

namespace App\Model;
use Util\Common;

/**
 * 首页banner-模型
 */
class MainBanner extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var string[]
     */
    public bool $timestamps = true;

    const MAIN = 'main';
    const DEVICE_HEADER = 'device_header';
    const DEVICE_FOOTER =  'device_footer';
    const PAY_DETAIL = 'pay_detail';

    protected ?string $table = 'main_banner';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = [
     'id','sort', 'thumb', 'url','image','is_del','type'
    ];
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected array $hidden = [
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
    ];

    /**获取首页外链图列表
     * @param array $where
     * @param array $sort
     * @param array $fields
     * @return array
     */
    public function get_list(array $where ,array $sort = ['field'=>'id','sort'=>'desc'],array $fields=['id','sort', 'thumb', 'url','image']) :array{
         return self::where($where)
        ->where('is_del',Common::DEL_SHOW)
        ->orderBy($sort['field'],$sort['sort'])
        ->get($fields)->toArray();
     }
}
